package top.v5it.japi.ddd.example.product.event;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.ApplicationEvent;
import org.springframework.kafka.core.KafkaTemplate;
import top.v5it.japi.ddd.example.product.configuration.EventConfiguration;

/**
 * @author zhanpu
 * @date 2023/11/17
 */
public class ProductReviewEvent extends ApplicationEvent {
    private static final long serialVersionUID = 8715017408324373319L;

    public ProductReviewEvent(Object source) {
        super(source);
    }

    public void sendProductReviewMessage() {
        @SuppressWarnings("unchecked") final KafkaTemplate<String, Object> kafkaTemplate = SpringUtil.getBean(KafkaTemplate.class);
        kafkaTemplate.send(EventConfiguration.TOPIC_NAME, source);
    }
}
